package com.demo.launcher;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.library.launcher.ActivityLauncher;
import com.library.launcher.OnActivityResultListener;

public class MainActivity extends AppCompatActivity {

    TextView tvText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tvText = findViewById(R.id.tvText);
        findViewById(R.id.toFragment).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityLauncher.with(MainActivity.this)
                        .withInt("type", 1)
                        .targetActivity(TargetFragmentActivity.class)
                        .launch();
            }
        });
        findViewById(R.id.toFragmentX).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityLauncher.with(MainActivity.this)
                        .withInt("type", 0)
                        .targetActivity(TargetFragmentActivity.class)
                        .launch();
            }
        });
        findViewById(R.id.toActivity).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityLauncher.with(MainActivity.this)
                        .targetActivity(TargetActivity.class)
                        .launch(new OnActivityResultListener() {
                            @Override
                            public void onActivityResult(int resultCode, Intent data) {
                                tvText.setText("onActivityResult:\n" + data.toUri(0));
                            }
                        });
            }
        });
        findViewById(R.id.toActivityExtra).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityLauncher.with(MainActivity.this)
                        .targetActivity(TargetActivity.class)
                        .withString("extra1", "string_extra")
                        .withInt("extra2", 100)
                        .launch(new OnActivityResultListener() {
                            @Override
                            public void onActivityResult(int resultCode, Intent data) {
                                tvText.setText("Extra, onActivityResult:\n" + data.toUri(0));
                            }
                        });
            }
        });
    }
}